<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class UserAddress extends Model {
    protected $fillable = [
        'province',
        'city',
        'district',
        'address',
        'zip',
        'contact_name',
        'contact_phone',
        'last_used_at',
    ];
    // 在json 中附加的属性
    // protected $appends = ['full_address'];

    protected $dates = ['last_used_at'];

    public function user() {
        return $this->belongsTo(User::class);
    }

    public function getFullAddressAttribute() {
        return $this->province.$this->city.$this->district.$this->address;
    }
}
